package com.jia.controller;

import com.jia.pojo.Dept;
import com.jia.service.DeptService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class DeptController {

    @Autowired
    DeptService deptService;

    @Autowired
    private DiscoveryClient discoveryClient;

    @HystrixCommand(fallbackMethod = "hystrixInfo")
    @GetMapping("/dept/info/{id}")
    public Dept info(@PathVariable("id") Long id) {
        Dept dept = deptService.selectById(id);
        if (dept == null){
            throw new RuntimeException("id==>"+id+"不存在改用户活着信息无法找到");
        }
        return dept;
    }
    // 备案方法
    public Dept hystrixInfo(@PathVariable("id") Long id) {
        return new Dept()
                .setDeptno(id)
                .setDname("id==>"+id+"不存在改信息 null Hystrix体现的")
                .setDbSource("no database exit");
    }
}
